package org.senseframework.support.open.api.controller.encrypt;


import org.senseframework.support.core.utils.DateUtils;

import java.io.Serializable;

/**
 * Author lanjian
 * Email  jianlan@iflytek.com
 */

public class ExchangeKey implements Serializable {
    private String password;
    private String key;
    private Long time;
    private Integer expire;

    public ExchangeKey() {

    }

    public ExchangeKey(String password, String key, Long time, Integer expire) {
        this.password = password;
        this.key = key;
        this.time = time;
        this.expire = expire;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public Long getTime() {
        return time;
    }

    public void setTime(Long time) {
        this.time = time;
    }

    public Integer getExpire() {
        return expire;
    }

    public void setExpire(Integer expire) {
        this.expire = expire;
    }

    public void validate() {
        Long now = DateUtils.nowDateTime();
        Long timeDiff = now - time;
        if (timeDiff > expire * 1000) {
            throw new EncryptException("validate time out");
        }
    }


    @Override
    public String toString() {
        return "KeyInfo{" +
                "password='" + password + '\'' +
                ", key='" + key + '\'' +
                ", time=" + time +
                ", expire=" + expire +
                '}';
    }
}
